//
//  SEChatExamineListCell.swift
//  SmartEyeForPatient
//
//  Created by QDSG on 2021/6/8.
//

import UIKit

protocol SEChatExamineListCellDelegate {
    func sendReportDidTapped(_ cell: SEChatExamineListCell, _ indexPath: IndexPath)
}

class SEChatExamineListCell: UITableViewCell {
    
    var delegate: SEChatExamineListCellDelegate?

    var indexPath = IndexPath(row: 0, section: 0)

    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }
    
    func update(with viewModel: SEExamineDetailViewModel, _ indexPath: IndexPath) {
        self.indexPath = indexPath
        nameLabel.text = viewModel.model.name
        timeLabel.text = viewModel.model.checkScheduleTime
        positionLabel.text = viewModel.model.checkEyePart
        hospitalLabel.text = viewModel.model.checkHosName
        collectionView.titles = viewModel.checkItemNamesArray
        
        frame = UIScreen.main.bounds
        layoutIfNeeded()
        collectionView.reloadData()
        let contentSize = collectionView.collectionViewLayout.collectionViewContentSize
        collectionViewHeightConstraint.constant = contentSize.height
    }
    
    @IBAction private func sendReportTapped() {
        delegate?.sendReportDidTapped(self, indexPath)
    }
    
    @IBOutlet private weak var sendReportBtn: UIButton! {
        didSet {
            sendReportBtn.isIgnoreEvent = false
        }
    }
    
    @IBOutlet private weak var nameLabel: UILabel!
    @IBOutlet private weak var timeLabel: UILabel!
    @IBOutlet private weak var positionLabel: UILabel!
    @IBOutlet private weak var hospitalLabel: UILabel!
    @IBOutlet private weak var collectionView: SETagsCollectionView!
    
    @IBOutlet private var collectionViewHeightConstraint: NSLayoutConstraint!
    
}
